home *** CD-ROM | disk | FTP | other *** search
/ Champak 122 / Vol 122.iso / games / sketchbo.swf / scripts / DefineSprite_207_mc_nurse / frame_1 / DoAction.as
Encoding:
Text File  |  2011-01-06  |  7.4 KB  |  384 lines

  1. if(!init)
  2. {
  3.    orig_scale = _xscale;
  4.    hitarea._visible = 0;
  5.    walking = false;
  6.    parrying = false;
  7.    attacking = false;
  8.    jumping = false;
  9.    fall_distance = 0;
  10.    init = true;
  11.    side = "L";
  12.    lastdecision = 0;
  13.    deadcount = 0;
  14.    floor = 62;
  15.    walkdistance = 25;
  16.    reach = 20;
  17.    hit2_reach = 75;
  18.    damage = 10;
  19.    total_ki = 20;
  20.    ki = total_ki;
  21.    ki_cost = 9;
  22.    pushfactor = 2;
  23.    total_hp = 70;
  24.    hp = total_hp;
  25.    regen_rate = 0.1;
  26.    score = 350;
  27.    _root.createPic("pic_nurse",this);
  28. }
  29. attacking = false;
  30. speed = 0;
  31. walking = false;
  32. this.onEnterFrame = function()
  33. {
  34.    if(!init)
  35.    {
  36.       return undefined;
  37.    }
  38.    if(dead)
  39.    {
  40.       deadcount++;
  41.       if(deadcount > 1000)
  42.       {
  43.          this.removeMovieClip();
  44.          unloadMovie(this);
  45.       }
  46.       gotoAndStop("die");
  47.       this._x -= _hitomi.speed;
  48.       return undefined;
  49.    }
  50.    lastdecision++;
  51.    onDie();
  52.    onWalk();
  53.    doCalcs();
  54.    var _loc3_ = fallback();
  55.    if(_loc3_ == undefined)
  56.    {
  57.       _loc3_ = 0;
  58.    }
  59.    var _loc4_ = _root.hitomi.speed;
  60.    checkHits();
  61.    decide();
  62.    this._x -= _loc4_;
  63.    this._x += _loc3_;
  64.    if(!walking && !attacking && !turning && !recieving)
  65.    {
  66.       unwalk();
  67.       gotoAndStop("stand");
  68.    }
  69. };
  70. checkHits = function()
  71. {
  72.    if(this.hitarea.hitTest(_hitomi.hitarea))
  73.    {
  74.       onHit();
  75.    }
  76.    if(_root.hitomi.hitTest(_X + club._x * getDirection(),_Y + club._y,true))
  77.    {
  78.       _root.hitomi.recieveHit(this);
  79.    }
  80.    if(_root.hitomi.hitTest(_X + (club._x + 3) * getDirection(),_Y + club._y,true))
  81.    {
  82.       _root.hitomi.recieveHit(this);
  83.    }
  84.    if(_root.hitomi.hitTest(_X + (club._x - 3) * getDirection(),_Y + club._y,true))
  85.    {
  86.       _root.hitomi.recieveHit(this);
  87.    }
  88. };
  89. doCalcs = function()
  90. {
  91.    if(!(walking || slashing || jumping || parrying || turning || recieving))
  92.    {
  93.       ki += regen_rate;
  94.    }
  95.    if(ki > total_ki)
  96.    {
  97.       ki = total_ki;
  98.    }
  99.    if(hp > total_hp)
  100.    {
  101.       hp = total_hp;
  102.    }
  103.    if(ki < 0)
  104.    {
  105.       ki = 0;
  106.    }
  107.    if(hp < 1)
  108.    {
  109.       hp = 0;
  110.       die();
  111.    }
  112.    pic.bars.hp._xscale = Math.ceil(hp / total_hp * 100);
  113.    pic.bars.ki._xscale = Math.ceil(ki / total_ki * 100);
  114. };
  115. getDirection = function()
  116. {
  117.    if(orig_scale == _xscale)
  118.    {
  119.       return 1;
  120.    }
  121.    return -1;
  122. };
  123. bombHit = function(hit_by, dmg, pushf)
  124. {
  125.    hp -= dmg;
  126. };
  127. onHit = function()
  128. {
  129.    _root.hitcount = _root.hitcount + 1;
  130.    if(_root.hitcount > 1000)
  131.    {
  132.       _root.hitcount = 0;
  133.    }
  134.    hp -= _hitomi.damage;
  135.    _root._score += _hitomi.damage;
  136.    var _loc3_ = _root.attachMovie("mc_blood01","blood" + hitcount,6000 + hitcount);
  137.    _loc3_._rotation = random(360);
  138.    var _loc4_ = random(150) + 100;
  139.    _loc3_._xscale = _loc4_;
  140.    _loc3_._yscale = _loc4_;
  141.    if(_hitomi.side == "R")
  142.    {
  143.       _loc3_._x = _hitomi._x + _hitomi.hitarea._x;
  144.       _loc3_._y = _hitomi._y + _hitomi.hitarea._y;
  145.    }
  146.    else
  147.    {
  148.       _loc3_._x = _hitomi._x - _hitomi.hitarea._x;
  149.       _loc3_._y = _hitomi._y + _hitomi.hitarea._y;
  150.    }
  151.    fall_distance = _hitomi.pushback * 2;
  152.    fallback = function()
  153.    {
  154.       fall_distance--;
  155.       if(fall_distance < 1)
  156.       {
  157.          delete this.fallback;
  158.          fall_distance = 0;
  159.          return 0;
  160.       }
  161.       return _hitomi.getDirection() * (fall_distance / 2);
  162.    };
  163.    soundsList = ["loud_metal_hit","blow01","beat","cabasa","zddd1kick1","zddd1kick2","zddd1tamb"];
  164.    playSound(soundsList);
  165. };
  166. die = function()
  167. {
  168.    _root.removePic(pic);
  169.    dead = true;
  170.    walking = false;
  171.    slashing = false;
  172.    attacking = false;
  173.    speed = 0;
  174.    gotoAndStop("die");
  175.    play();
  176. };
  177. decide = function()
  178. {
  179.    if(dead)
  180.    {
  181.       return undefined;
  182.    }
  183.    if(!walking && !attacking || lastdecision > 70)
  184.    {
  185.       lastdecision = 0;
  186.       var _loc2_ = random(20);
  187.       attacking = false;
  188.       if(_loc2_ == 0)
  189.       {
  190.          walk_distance = random(walkdistance) + 6;
  191.          walk();
  192.          return undefined;
  193.       }
  194.       var _loc1_ = Math.abs(_hitomi._x - _X);
  195.       if(_loc2_ < 3)
  196.       {
  197.          if(_loc1_ < 10 || _loc1_ > reach)
  198.          {
  199.             if(_hitomi._x < _X)
  200.             {
  201.                left();
  202.             }
  203.             else
  204.             {
  205.                right();
  206.             }
  207.             return undefined;
  208.          }
  209.       }
  210.       if(_loc1_ < reach + 5 && _loc1_ > 20)
  211.       {
  212.          if(_hitomi._x > _X && side == "L")
  213.          {
  214.             turn("R");
  215.          }
  216.          if(_hitomi._x < _X && side == "R")
  217.          {
  218.             turn("L");
  219.          }
  220.          attack();
  221.          return undefined;
  222.       }
  223.       if(_loc1_ < hit2_reach && _loc1_ > reach)
  224.       {
  225.          if(_hitomi._x > _X && side == "L")
  226.          {
  227.             turn("R");
  228.          }
  229.          if(_hitomi._x < _X && side == "R")
  230.          {
  231.             turn("L");
  232.          }
  233.          attack2();
  234.          return undefined;
  235.       }
  236.       if(_loc1_ < reach)
  237.       {
  238.          walk_distance = random(walkdistance) + 6;
  239.          walk();
  240.          return undefined;
  241.       }
  242.       unwalk();
  243.       gotoAndStop("stand");
  244.    }
  245. };
  246. attack = function()
  247. {
  248.    if(!attacking)
  249.    {
  250.       if(ki < ki_cost)
  251.       {
  252.          walking = false;
  253.          attacking = false;
  254.          walk_distance = random(walkdistance) + 6;
  255.          walk();
  256.          return undefined;
  257.       }
  258.       walking = false;
  259.       speed = 0;
  260.       attacking = true;
  261.       ki -= ki_cost;
  262.       gotoAndStop("hit");
  263.       play();
  264.    }
  265. };
  266. attack2 = function()
  267. {
  268.    if(!attacking)
  269.    {
  270.       if(ki < ki_cost)
  271.       {
  272.          walking = false;
  273.          attacking = false;
  274.          walk_distance = random(walkdistance) + 6;
  275.          walk();
  276.          return undefined;
  277.       }
  278.       walking = false;
  279.       speed = 0;
  280.       attacking = true;
  281.       ki -= ki_cost;
  282.       gotoAndStop("hit2");
  283.       play();
  284.    }
  285. };
  286. if(!init)
  287. {
  288.    side = "L";
  289.    orig_scale = _xscale;
  290.    init = true;
  291. }
  292. right = function()
  293. {
  294.    turn("R");
  295. };
  296. left = function()
  297. {
  298.    turn("L");
  299. };
  300. turn = function(sideto)
  301. {
  302.    if(!sideto)
  303.    {
  304.       if(side == "L")
  305.       {
  306.          sideto = "R";
  307.       }
  308.       else
  309.       {
  310.          sideto = "L";
  311.       }
  312.    }
  313.    if(side != sideto)
  314.    {
  315.       if(!jumping)
  316.       {
  317.          turnTo = sideto;
  318.          walking = false;
  319.          jumping = false;
  320.          parrying = false;
  321.          attacking = false;
  322.          if(sideto == "L")
  323.          {
  324.             _xscale = orig_scale;
  325.          }
  326.          else
  327.          {
  328.             _xscale = - orig_scale;
  329.          }
  330.          side = sideto;
  331.       }
  332.    }
  333.    else
  334.    {
  335.       turning = false;
  336.       walk_distance = random(walkdistance) + 6;
  337.       walk();
  338.    }
  339. };
  340. walk = function()
  341. {
  342.    if(walking || attacking || jumping || parrying || turning || dead)
  343.    {
  344.       return undefined;
  345.    }
  346.    walking = true;
  347.    gotoAndStop("walk");
  348.    play();
  349.    this.count = 0;
  350.    this.onWalk = function()
  351.    {
  352.       count++;
  353.       walking = true;
  354.       if(side == "R")
  355.       {
  356.          _X = _X + 1.5;
  357.       }
  358.       else
  359.       {
  360.          _X = _X - 1.5;
  361.       }
  362.       if(count > Math.abs(walk_distance))
  363.       {
  364.          delete this.onWalk;
  365.          walking = false;
  366.          unwalk();
  367.       }
  368.    };
  369. };
  370. unwalk = function()
  371. {
  372.    if(walking && !dead)
  373.    {
  374.       walking = false;
  375.       speed = 0;
  376.       gotoAndStop("stand");
  377.    }
  378. };
  379. playSound = function(ids)
  380. {
  381.    _root.sounds.playSound(ids);
  382. };
  383. stop();
  384.